<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('【请填写功能名称】列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">


            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:vgroup:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:vgroup:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:vgroup:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:vgroup:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:vgroup:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:vgroup:remove')}]];
        var prefix = ctx + "system/vgroup";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "vip用户组",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'vgroupname',
                    title: '用户组'
                },
                {
                    field: 'vipdays',
                    title: 'vip时长(天)'
                },
                {
                    field: 'discount',
                    title: '阅读折扣'
                },
                {
                    field: 'discount2',
                    title: '下载折扣'
                },
                {
                    field: 'downcount',
                    title: '日下载上限'
                },
                {
                    field: 'downcount2',
                    title: '总下载上限'
                },
                {
                    field: 'docmoney',
                    title: 'VIP免费文档价格上限',
                    formatter: function(value, item, index) {
                        if (value == -1) {
                            return '<span class="label label-success">不限制</span>';
                        }
                        else{
                            return '<span class="label label-primary">'+value+'元</span>';
                        }

                    }
                },
                {
                    field: 'cash2',
                    title: '价格'
                },

                {
                    visible: editFlag == 'hidden' ? false : true,
                    title: '推荐',
                    formatter: function (value, row, index) {
                        return statusTools1(row);
                    }
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    title: '启用',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.vgroupid + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.vgroupid + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);

        });
        function statusTools(row) {
            if (row.state == 0) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.vgroupid + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.vgroupid + '\')"></i> ';
            }
        }
        function statusTools1(row) {
            if (row.suggest == 0) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable1(\'' + row.vgroupid + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable1(\'' + row.vgroupid + '\')"></i> ';
            }
        }
        function enable(groupid) {
            $.modal.confirm("确认要启用吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "vgroupid": groupid, "state": 1 });
            })
        }
        function disable(groupid) {
            $.modal.confirm("确认要停用吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "vgroupid": groupid, "state": 0 });
            })
        }
        function enable1(groupid) {
            $.modal.confirm("确认要启用吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "vgroupid": groupid, "suggest": 1 });
            })
        }
        function disable1(groupid) {
            $.modal.confirm("确认要停用吗？", function() {
                $.operate.post(prefix + "/changeStatus", { "vgroupid": groupid, "suggest": 0 });
            })
        }
    </script>
</body>
</html>